package com.sinosoft.electronicinsure;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinosoft.R;

public class RiskInfoListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<RiskInfoListItem> mRiskInfoListItems;

	public RiskInfoListAdapter(Context mContext,
			List<RiskInfoListItem> mRiskInfoListItems) {
		mInflater = LayoutInflater.from(mContext);
		this.mRiskInfoListItems = mRiskInfoListItems;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mRiskInfoListItems.size();
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return mRiskInfoListItems.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.riskinfolistitem, null);
			viewHolder.tv_RiskName = (TextView) convertView
					.findViewById(R.id.riskname);
			viewHolder.tv_InsuYear = (TextView) convertView
					.findViewById(R.id.insuyear);
			viewHolder.tv_PayEndYear = (TextView) convertView
					.findViewById(R.id.payendyear);
			viewHolder.tv_PayIntv = (TextView) convertView
					.findViewById(R.id.payintv);
			viewHolder.tv_Prem = (TextView) convertView.findViewById(R.id.prem);
			viewHolder.tv_Amnt = (TextView) convertView.findViewById(R.id.amnt);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.tv_RiskName.setText(mRiskInfoListItems.get(position)
				.getRiskName());
		viewHolder.tv_InsuYear.setText(mRiskInfoListItems.get(position)
				.getInsuYear());
		viewHolder.tv_PayEndYear.setText(mRiskInfoListItems.get(position)
				.getPayEndYear());
		viewHolder.tv_PayIntv.setText(mRiskInfoListItems.get(position)
				.getPayIntv());
		viewHolder.tv_Prem.setText(mRiskInfoListItems.get(position).getPrem());
		viewHolder.tv_Amnt.setText(mRiskInfoListItems.get(position).getAmnt());
		return convertView;
	}

	static class ViewHolder {
		TextView tv_RiskName;
		TextView tv_InsuYear;
		TextView tv_PayEndYear;
		TextView tv_PayIntv;
		TextView tv_Prem;
		TextView tv_Amnt;
		ImageView iv_Delete;
	}
}
